<?php

namespace App\Models\System;

use App\Models\Common\Media;
use Dcat\Admin\Models\Administrator;
use Dcat\Admin\Traits\HasDateTimeFormatter;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\SoftDeletes;
use Spatie\EloquentSortable\Sortable;
use Spatie\EloquentSortable\SortableTrait;

class GoodsCategory extends Model implements Sortable
{
	use HasDateTimeFormatter;
    use SoftDeletes;

    use SortableTrait;

    protected $sortable = [
        'order_column_name' => 'order',
        'sort_when_creating' => true,
    ];

    protected $guarded = [];

    protected $table = 'goods_categories';

    public function icon() : BelongsTo
    {
        return $this->belongsTo(Media::class, 'icon_id');
    }

    public function creator() : BelongsTo
    {
        return $this->belongsTo(Administrator::class, 'creator_id');
    }
}
